<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<import type='css' file="Css.admin.admin" />  -->
<?php echo $css_file,$css_tree;?>
<title>后台管理</title>
</head>

<body>
<div class="main">
<div class="crumbs">
	当前位置：<span id="current_pos">设置->贴士设置</span>
	</div>
    <div id="right_main" class="m_content" style="height: 241px;">
        		<div class="btn">
    				<label for="">操作</label>
    				<input type="submit" value="添加" id="add" name="dosubmit" class="button" />
    				<input type="submit" value="编辑" id="edit" name="dosubmit" class="button" />
    				<input type="submit" value="删除" id="del" name="dosubmit" class="button" />
    			</div>
    		<div class="show">
				<ul id="tipstree" class="ztree"></ul>
			</div>
        <div class="clear"></div>
	</div>
</div>
<?php echo $js_file,$js_tree;?>
<script type="text/javascript">
//<![CDATA[
$(function(){
	var setting = {
			view: {
				dblClickExpand: false,
				showLine: false,
				selectedMulti: false
			},
			edit:{
				enable:true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			async:{
				enable:true,
				url:"__GROUP__/Setting/getchildren",
				autoParam:["id"]
			},
			callback: {
				onClick: clickNode
			}
		};
		$.getJSON("__GROUP__/Setting/gettiptree", function(zNodes) {
			$.fn.zTree.init($("#tipstree"), setting, zNodes);
		});
		function clickNode(event, treeId, treeNode){
			var zTree = $.fn.zTree.getZTreeObj("tipstree");
			zTree.expandNode(treeNode);
		}

		$("#add").click(function(){
			var zTree = $.fn.zTree.getZTreeObj("tipstree");
			nodes = zTree.getSelectedNodes();
			treeNode = nodes[0];
			if(treeNode==undefined){
				$.dialog({icon:'warning',content:'请先选择节点再进行添加操作',time:3});
				return;
	    	}
			var html = '<form id="opstu">';
			html+= '<div><label>名称:</label>';
			html+= '<input type="text" name="name"/></div>';
			html+= '</form>';
			$.dialog({
				title:'添加菜单',
				fixed:true,
			    resize: false,
			    ok:true,
			    cancelVal: '取消',
			    cancel: true,
		    	content:html,
		    	ok:function(){
					var name = $("#opstu input[name='name']").val();
					if(trim(name)==""){
						$.dialog({icon:'warning',content:'菜单名字不能为空',time:3});
						return false;
					}
					$.post("__GROUP__/Setting/addtree",{pid:treeNode.id,name:name},function(datas){
						var newnode =  {name:name,pId:treeNode.id};
						if(datas){
							if(treeNode.isParent){
								zTree.addNodes(treeNode,newnode);
							}else{
								zTree.reAsyncChildNodes(treeNode.getParentNode(),"refresh");
							}
							$.dialog({icon:'succeed',content:'操作成功',time:2});
							
						}else{
							$.dialog({icon:'error',content:'操作失败',time:2});
						}
					});
		        }
				
			});

		});
	
});


//]]>
</script>
</body>
</html>